package org.jeecg.modules.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.entity.ProjectProfessorInfo;
import org.jeecg.modules.mapper.DiyProfessorInfoMapper;
import org.jeecg.modules.mapper.ProjectOwnProfessorMapper;
import org.jeecg.modules.service.ProjectOwnProfessorService;
import org.jeecg.modules.vo.Professor;
import org.jeecg.modules.vo.ProjectOwnProfessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : ShiJianlong
 * @date : 2020/7/9 13:00
 */
@Service
public class ProjectOwnProfessorServiceImpl extends ServiceImpl<ProjectOwnProfessorMapper, ProjectOwnProfessor> implements ProjectOwnProfessorService {
    @Autowired
    ProjectOwnProfessorMapper projectOwnProfessorMapper;
    @Autowired
    DiyProfessorInfoMapper diyProfessorInfoMapper;
    @Override
    public Page<ProjectOwnProfessor> queryByProjectId(Page<ProjectOwnProfessor> page,String projectId) {
        List<ProjectOwnProfessor> projectOwnProfessorMappers = projectOwnProfessorMapper.queryByProjectId(projectId);
        for (ProjectOwnProfessor projectOwnProfessor:projectOwnProfessorMappers
        ) {
            if(ProjectProfessorInfo.projectStage.RUNNING==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.抽取中);
            }else if(ProjectProfessorInfo.projectStage.FINISH==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.已完成);
            }else if (ProjectProfessorInfo.projectStage.WARN==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.专家库人数不足);
            } else if (ProjectProfessorInfo.projectStage.BEGIN==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.未抽取);
            }else if (ProjectProfessorInfo.projectStage.WAIT==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.待确认);
            }else if (ProjectProfessorInfo.projectStage.OVER==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.已结束);
            }
            for (Professor professor: projectOwnProfessor.getProject().getProfessorList()
            ) {
                if(("1").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("同意");
                }else if(("2").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("待审核");
                }else if(("0").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("拒绝");
                }else if(("-1").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("等待管理员确认");
                }else if(("-3").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("管理员删除");
                }else if(("-4").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("临时有事请假");
                }
                else if(("-5").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("专家确认超时处理");
                }
                //查询在项目中的职位
                String name = diyProfessorInfoMapper.selDictNameById(professor.getProfessorInProjectProfessorType());
                professor.setProfessorInProjectProfessorType(name);
            }
        }
        //手动更改分页
        return page.setRecords(projectOwnProfessorMappers);
    }
    @Override
    public Page<ProjectOwnProfessor> queryPage(Page<ProjectOwnProfessor> page) {
        List<ProjectOwnProfessor> projectOwnProfessorMappers = projectOwnProfessorMapper.queryPage();
        for (ProjectOwnProfessor projectOwnProfessor:projectOwnProfessorMappers
        ) {
            if(ProjectProfessorInfo.projectStage.RUNNING==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.抽取中);
            }else if(ProjectProfessorInfo.projectStage.FINISH==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.已完成);
            }else if (ProjectProfessorInfo.projectStage.WARN==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.专家库人数不足);
            } else if (ProjectProfessorInfo.projectStage.BEGIN==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.未抽取);
            }else if (ProjectProfessorInfo.projectStage.WAIT==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.待确认);
            }else if (ProjectProfessorInfo.projectStage.OVER==(projectOwnProfessor.getProject().getProjectStatus())){
                projectOwnProfessor.getProject().setProjectStatus(ProjectProfessorInfo.projectStage.已结束);
            }
            for (Professor professor: projectOwnProfessor.getProject().getProfessorList()
            ) {
                if(("1").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("同意");
                }else if(("2").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("待审核");
                }else if(("0").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("拒绝");
                }else if(("-1").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("等待管理员确认");
                }else if(("-3").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("管理员删除");
                }else if(("-4").equals(professor.getProfessorInProjectStates())){
                    professor.setProfessorInProjectStates("临时有事请假");
                }
                //查询在项目中的职位
                String name = diyProfessorInfoMapper.selDictNameById(professor.getProfessorInProjectProfessorType());
                professor.setProfessorInProjectProfessorType(name);
            }
        }
        //手动更改分页

        return page.setRecords(projectOwnProfessorMappers);
    }
}
